package com.chara.rabbitmq_demo.com.chara.rabbitmq.work;

import com.chara.rabbitmq_demo.com.chara.rabbitmq.utils.ConnectionUtil;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

/**
 * @Classname Producer
 * @Description 工作队列消息生产者
 * @Date 2025/10/8 21:30
 * @Author Chara
 */
public class Producer {
    public static final String QUEUE_NAME = "work_queue";

    public static void main(String[] args) throws Exception {
        Connection connection = ConnectionUtil.getConnection();

        Channel channel = connection.createChannel();

        channel.queueDeclare(QUEUE_NAME, true, false, false, null);

        for (int i = 0;  i <= 10; i ++){
            String body = i + "Hello work queue!";

            channel.basicPublish("", QUEUE_NAME, null, body.getBytes());
        }

        channel.close();
        connection.close();

    }

}
